"use strict";
// function xxxxx(参数列表){
//     方法体
// }
function sayHi(name, age) {
    return `hello  ${name},几年 ${age}岁`;
}
let name = '张飞';
let age = 18;
let wel = sayHi(name, age);
console.log(wel);
//定义一个变量 指向的是function
let myfun = sayHi;
myfun(name, age);
/**
 * 定义打招呼的方法
 * @param name  姓名
 * @returns  String
 */
function sayHi2(name) {
    return `hello  ${name}`;
}
//我希望myfunc2 代表的是 function(name:string):string
//我希望myfunc2 代表的是 function(name:string,age:number):string
let myfunc2; //ts特有的语法
myfunc2 = sayHi2;
let result = myfunc2(name);
console.log(result);
//操作两个数
let operator2Nums;
function sum(a, b) {
    console.log("两个数加法的值 " + (a + b));
    return a + b;
}
function multiplication(a, b) {
    console.log("两个数乘积的值 " + (a * b));
    return a * b;
}
//加法运算
operator2Nums = sum;
operator2Nums(10, 20);
//乘法
operator2Nums = multiplication;
operator2Nums(10, 20);
//可选参数的function
function buildName(firstName = "Hello", lastName) {
    if (lastName) {
        return firstName + ' ' + lastName;
    }
    else {
        return firstName;
    }
}
let tomcat = buildName('Tom', 'Cat');
let tom = buildName(undefined, 'Tom');
console.log(tom);
//参数默认值
function axios(url, method = "get") {
    console.log(`发起网络（${method}）请求,地址 ：${url}`);
}
axios('http://localhost:8080/server', 'get');
axios('http://localhost:8080/baidu', 'post');
axios('http://localhost:8080/server');
function reverse(x) {
    if (typeof x === 'number') {
        return Number(x.toString().split('').reverse().join(''));
    }
    else if (typeof x === 'string') {
        return x.split('').reverse().join('');
    }
}
reverse("123456");
reverse(123456);
